<template>
	<view class="address-page">
		<view class="address-box">
			<view class="address-box-item relative flex-direction-column" v-for="(item, index) in list" :key="index">
				<image v-if="commonConfigs && commonConfigs.domainFrontFileLink" :src="`${commonConfigs.domainFrontFileLink}/files/images/user/address-box-bg.png`" class="bg" />
				
				<view @click="select(item)" class="relative">
					<view class="top flex">
						<view>{{ item.name }}</view>
						<view class="phone">{{ item.phone }}</view>
					</view>

					<view class="address">{{ item.province }}{{ item.city }}{{ item.area }}{{ item.detail }}</view>
				</view>

				<view class="flex bottom absolute flex-justify-content-between">
					<view class="bottom-left flex" @click.stop="clickRadio(item, index)">
						<view class="relative flex-all-center" v-if="commonConfigs && commonConfigs.domainFrontFileLink" style="width: 25rpx;height: 25rpx;">
							
							<image v-if="item.is_default !== 0" src="/static/images/public_imgs/selecting.png" style="width: 24rpx; height: 24rpx" mode=""> </image>
							<image v-else src="/static/images/public_imgs/select.png" style="width: 24rpx; height: 24rpx" mode=""> </image>
						
						</view>
						
						<view class="radio-text">设为默认</view>
					</view>
					<view class="bottom-right flex">
						<view class="btn relative" @click.stop="modify(item)">
							<image v-if="commonConfigs && commonConfigs.domainFrontFileLink" :src="`${commonConfigs.domainFrontFileLink}/files/images/user/address-btn-edit.png`" class="bg" />
						</view>
						<view class="btn relative" @click.stop="clickDelete(item)">
							<image v-if="commonConfigs && commonConfigs.domainFrontFileLink" :src="`${commonConfigs.domainFrontFileLink}/files/images/user/address-btn-del.png`" class="bg" />
						</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 按钮 -->
		<view class="submit-btn relative" @click="goToAdd">
			<image v-if="commonConfigs && commonConfigs.domainFrontFileLink" :src="`${commonConfigs.domainFrontFileLink}/files/images/user/basic-info-submit-btn-bg.png`" class="bg" />
			<view class="relative">
				添加新地址
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'addressPage',
		props: {
			list: Array,
			fromType: String
		},
		data() {
			return {};
		},
		computed: {
			commonConfigs() {
				return this.$store.getters.commonConfigs || {};
			},
		},
		methods: {
			// 添加新地址
			goToAdd() {
				uni.navigateTo({
					url: '/secondary/addressInfoPage/addressInfoPage'
				});
			},
			select(item) {
				if ( !this.fromType ) return
			
				this.$store.commit('ADDRESS_SET_FUN', item);
				uni.navigateBack({});
			},
			
			// 删除
			async clickDelete(item) {
				this.$emit('clickDelete', item);
			},
			// 修改
			modify(item) {
				uni.navigateTo({
					url: '/secondary/addressInfoPage/addressInfoPage?type=' + 'modify' + '&item=' + JSON.stringify(item)
				});
			},
			async clickRadio(item) {
				this.$emit('clickRadio', item);
			},
			
		}
	};
</script>

<style lang="scss" scoped>
	.address-page {
		width: 100%;
		.address-box {
			width: 710rpx;

			font-size: 28rpx;
			color: #FFFFFF;
			margin: 0 auto;
			.address-box-item {
				width: 100%;
				height: 314rpx;
				padding: 50rpx 40rpx;
				margin-bottom: 20rpx;
				
				.phone {
					color: #FFFFFF;
					margin-left: 25rpx;
				}
				.address {
					color: #FFFFFF;
					padding: 20rpx 0;
					word-break: break-all;
				}
				.bottom {
					width: 90%;
					bottom: 32rpx;
					align-items: center;
					justify-content: space-between;
					border-top: 1rpx solid #FFFFFF;
					padding-top: 30rpx;
					.bottom-left {
						align-items: center;
						.icon-radio {
							width: 24rpx;
							height: 24rpx;
						}
						.radio-text {
							color: #FFFFFF;
							font-size: 20rpx;
							margin-left: 20rpx;
						}
					}
					.bottom-right {
						.btn {
							width: 110rpx;
							height: 40rpx;
							margin: 0 10rpx;
						}
					}
				}
			}
		}
		.submit-btn {
			width: 512rpx;
			height: 76rpx;
			font-size: 28rpx;
			color: #4470FF;
			font-weight: bold;
			line-height: 76rpx;
			text-align: center;
			margin: 77rpx auto;
		}
	}
</style>
